package com.sicheng.lc.杂题.滑动窗口专题;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/13 12:19
 */
public class 乘积小于K的子数组 {
    //https://leetcode.cn/problems/subarray-product-less-than-k/
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        long cur = 1;
        int res = 0;
        for (int j = 0, i = 0; j < nums.length; j++) {
            cur *= nums[j];
            while (i <= j && cur >= k) {
                cur /= nums[i];
                i++;
            }
            res += j - i + 1;
        }
        return res;
    }
}
